import "reflect-metadata";

const clickMetadataKey = Symbol("click");
// export Function
export function BindEvent(target: any, propertyName: string, descriptor: any) {
    let method = descriptor.value as Function;
    console.log(target.containerId)
    descriptor.value = function () {
        console.log(target.containerId)
        let requiredParameters: number[] = Reflect.getOwnMetadata(clickMetadataKey, target, propertyName);
        if (requiredParameters) {
            for (let parameterIndex of requiredParameters) {
                if (parameterIndex >= arguments.length || arguments[parameterIndex] === undefined) {
                    throw new Error("Missing required argument.");
                }
            }
        }
        return method.apply(this, arguments);
    }
}
export function click(target: Object, propertyKey: string | symbol, parameterIndex: any) {
    console.log(arguments)
    let existingRequiredParameters: number[] = Reflect.getOwnMetadata(clickMetadataKey, target, propertyKey) || [];
    existingRequiredParameters.push(parameterIndex);
    Reflect.defineMetadata(clickMetadataKey, existingRequiredParameters, target, propertyKey);
}